package com.wechat.dto;

import java.io.Serializable;
import java.util.List;

import com.alibaba.fastjson.annotation.JSONField;
import com.swak.Constants;
import com.swak.entity.Page;
import com.swak.persistence.Classify;
import com.swak.security.Principal;
import com.swak.utils.Lists;
import com.swak.utils.bean.BeanCopier;
import com.swak.utils.bean.BeanCopiers;
import com.wechat.entity.Message;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * 消息
 * 
 * @author Auto Generator
 * @date 2022-10-21T23:59:27.286447600
 */
@Getter
@Setter
@Accessors(chain = true)
public class MessageDTO implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@lombok.EqualsAndHashCode.Exclude
	@lombok.ToString.Exclude
	private static final transient BeanCopier<MessageDTO, Message> Copier = BeanCopiers.create(MessageDTO.class, 
	        Message.class);
	
	private Long id;
	private Long sequence;
	private Byte isSender;
	private String talker;
	private Byte msgType;
	private String msgBrief;
	private String msgContent;
	private Integer msgFlag;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime createDate;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime updateDate;
	@JSONField(format = Constants.Second_Format)
	private java.time.LocalDateTime delAt;
	
	/**
	 * 操作人的身份
	 */
	private Principal principal;
	
	/**
	 * DTO 转换为 PO
	 *
	 * @param entity
	 * @return DTO
	 */
	public Message transform() {
		return Copier.transform(this);
	}
	
	/**
	 * DTOS 转换为 POS
	 *
	 * @param dtos
	 * @return DTOs
	 */
	public static List<Message> transform(List<MessageDTO> dtos) {
	    List<Message> pos = Lists.newArrayList();
	    if (dtos == null) { return pos;}
	    for (MessageDTO dto: dtos) {
	    	pos.add(dto.transform());
	    }
		return pos;
	}
	
	/**
	 * PO 转换为 DTO
	 *
	 * @param entity
	 * @return DTO
	 */
	public static MessageDTO convert(Message entity) {
	    if (entity == null) { return null;}
		return Copier.convert(entity);
	}
	
	/**
	 * POS 转换为 DTOS
	 *
	 * @param entitys
	 * @return DTOs
	 */
	public static List<MessageDTO> convert(List<Message> entitys) {
	    List<MessageDTO> dtos = Lists.newArrayList();
	    if (entitys == null) { return dtos;}
	    for (Message entity: entitys) {
	    	dtos.add(MessageDTO.convert(entity));
	    }
		return dtos;
	}
	
	/**
	 * Page 转换为 Page
	 *
	 * @param entity
	 * @return DTO
	 */
	public static Page<MessageDTO> convert(Page<Message> page) {
		return Page.of(page.getParam(), MessageDTO.convert(page.getData()));
	}
	
	/**
	 * classify 分类
	 *
	 * @param dtos
	 * @param pos
	 * @return Classify
	 */
	public static Classify<Message> classify(List<MessageDTO> dtos, List<Message> pos) {
		return Classify.of(MessageDTO.transform(dtos), pos);
	}
	
	/**
	 * 创建DTO
	 *
	 * @return DTO
	 */
	public static MessageDTO of() {
	    return new MessageDTO();
	}
}
